scriptencoding utf-8

" 声明vimhome
let g:vimhome=fnamemodify(resolve(expand('<sfile>:p')), ':h')

" 重置leader
let mapleader=','
let maplocalleader=';'

" 重置runtimepath
let &runtimepath=g:vimhome.'/runtime'.',$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,'.g:vimhome.'/runtime/after'

" 有关插件声明的配置
let g:loaded_completion_plugin = 0
let g:completion_plugin = 'coc.nvim'
let g:file_explorer_plugin = 'fern'
let g:commentary_plugin = 'vim-commentary'
let g:disable_ale = 1

" 加载 matchit 插件，貌似可以用 Plug 加载
if v:version >= 800 && !has('nvim')
    packadd! matchit
endif

function s:ResolvePlugPath(settings_path)
    let extension = fnamemodify(a:settings_path, ':e')
    if !empty(extension)
        " TODO: 忘记输入 let
        let extension = '.'.extension
    endif
    return fnamemodify(a:settings_path, ':r').'-plug'.extension
endfunction

if empty($VIM_MAIN)
    let $VIM_MAIN = g:vimhome.'/config/main.vim'
endif
let $VIM_MAIN_PLUG = s:ResolvePlugPath($VIM_MAIN)

" 使用 Plug 管理插件
call plug#begin(g:vimhome.'/bundle') " 插件声明 {{{
    " 加载基础插件
    execute 'source '.g:vimhome.'/config/base-plug.vim'

    " 加载 main plugins
    if filereadable($VIM_MAIN_PLUG)
        source $VIM_MAIN_PLUG
    end

    " 加载本地插件
    if filereadable(g:vimhome.'/config/local-plug.vim')
        execute 'source '.g:vimhome.'/config/local-plug.vim'
    endif
call plug#end() " }}}

execute 'source '.g:vimhome.'/config/base.vim'

" 加载 main settings
if filereadable($VIM_MAIN)
    source $VIM_MAIN
else
    echom '找不到 main 配置文件：'.$VIM_MAIN
end

" 加载本地配置
if filereadable(g:vimhome.'/config/local.vim')
    execute 'source '.g:vimhome.'/config/local.vim'
endif
